﻿<%@ page import="com.railway.msg.model.*"%>
<%@ page import="java.util.*"%>


<%@ page import="com.railway.system.model.SysDept"%>
<%@ page import="com.railway.system.model.SysUser"%>
<%@ page import="com.railway.common.util.StaticMethod"%>
<%@ page import="java.util.List"%>
<%@ page import="com.railway.common.constants.SysConstant"%>
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/commons/taglibs.jsp"%>
<html>
	<head>	
		<title><%=MsgSend.TABLE_ALIAS%>新增</title>
	    <link rel="stylesheet" type="text/css" href="${ctx}/css/default.css" />
		<link rel="stylesheet" href="${ctx}/css/ztree.css" type="text/css">
		<link rel="stylesheet" href="${ctx}/css/zTreeStyle/zTreeStyle.css"	type="text/css">
		<link href="${ctx}/commons/upload/css/uploadify.css" rel="stylesheet" type="text/css" />
		<script type="text/javascript" src="${ctx}/scripts/jquery-1.4.2.min.js"></script>
		<script type="text/javascript"	src="${ctx}/scripts/jquery.easyui.min.js"></script>
		<script type="text/javascript"	src="${ctx}/scripts/locale/easyui-lang-zh_CN.js"></script>
		<script type="text/javascript"	src="${ctx}/scripts/jquery-1.4.4.min.js"></script>
		<script type="text/javascript" src="${ctx}/commons/upload/js/swfobject.js"></script>
		<script type="text/javascript"	src="${ctx}/commons/upload/js/jquery.uploadify.v2.1.4.js"></script>
		<script type="text/javascript"	src="${ctx}/scripts/jquery.ztree.core-3.0.min.js"></script>
		<script type="text/javascript"	src="${ctx}/scripts/jquery.ztree.excheck-3.0.min.js"></script>
		<script type="text/javascript" src="${ctx}/scripts/easyTooltip.js"></script>
		<style>
		body {
		margin:0;
		padding:40px;
		background:#fff;
		font:80% Arial, Helvetica, sans-serif;
		color:#555;
		line-height:180%;
	}
h1{
	font-size:180%;
	font-weight:normal;
	}
h2{
	font-size:160%;
	font-weight:normal;
	}	
h3{
	font-size:140%;
	font-weight:normal;
	}	
img{border:none;}
pre{
	display:block;
	font:12px "Courier New", Courier, monospace;
	padding:10px;
	border:1px solid #bae2f0;
	background:#e3f4f9;	
	margin:.5em 0;
	}		

/* Easy Tooltip */

#easyTooltip{
	padding:5px 10px;
	border:1px solid #195fa4;
	background:#195fa4 url(bg.gif) repeat-x;
	color:#fff;
	}

#easyTooltip2{
	padding:5px 10px;
	border:1px solid #5e5e5e;
	background:#5e5e5e url(bg2.gif) repeat-x;
	color:#fff;
	width:160px;
	}
#easyTooltip2 h4, #easyTooltip2 p{
	margin:.25em 0;
	}	
					

/* // Easy Tooltip */

</style>
		
		<script type="text/javascript"> 
		function deleteUploadedFiles(){
	      jQuery('#fileupload').uploadifyClearQueue();
	      form1.uploadedfileid.value = "";
	      $('.files').empty();
        
	     /* if(form1.uploadedfileid.value == '') return;
		     $.get("${ctx}/files/Files/deleteByAjax.do?t="+Math.random(), {
                Action:"get","fileTypes":"ADDRESS",uploadedfileid:form1.uploadedfileid.value}, function (data, textStatus){	
   	              $('.files').empty();
         		  $('#filename').empty();
         		  form1.uploadedfileid.value = "";
         		
     
		   });	   */
	}
           function test(){
      
           
           }
	        var setting = {
			    check: {
				enable: true,
				chkboxType: { "Y" : "ps", "N" : "ps" }
			   },
			view: {
				dblClickExpand: false
			},
			data: {
				simpleData: {
					enable: true
				}
			},
			callback: {
				beforeClick: beforeClick,
				onCheck: onCheck
			}
		};


     
		function beforeClick(treeId, treeNode) {
			var zTree = $.fn.zTree.getZTreeObj("treeDemo");
			zTree.checkNode(treeNode, !treeNode.checked, null, true);
			return false;
		}
		
		function onCheck(e, treeId, treeNode) {

			var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
			nodes = zTree.getCheckedNodes(true),
			v = "";
	
			for (var i=0, l=nodes.length; i<l; i++) {
				if(nodes[i].type == 1){
				var tt = nodes[i].id;
		     	form1.targetids.value +=   tt.substring(1,tt.length) + ",";
				v += nodes[i].name + ",";}
			}
			if (v.length > 0 ) v = v.substring(0, v.length-1);
			var cityObj = $("#citySel");
			cityObj.attr("value", v);
		}

		function showMenu() {
			var cityObj = $("#citySel");			
			var cityOffset = $("#citySel").offset();			
			$("#menuContent").css({left:cityOffset.left + "px", top:cityOffset.top + cityObj.outerHeight() + "px"}).slideDown("fast");
			$("body").bind("mousedown", onBodyDown);
		}
		function hideMenu() {
			$("#menuContent").fadeOut("fast");
			$("body").unbind("mousedown", onBodyDown);
		}
		function onBodyDown(event) {
			if (!(event.target.id == "menuBtn" || event.target.id == "citySel" || event.target.id == "menuContent" || $(event.target).parents("#menuContent").length>0)) {
				hideMenu();
			}
		}
		//通过部门选择人员
		function selectusersbydept(obj){
		        if(obj.checked == true){
   		    	$("input[name^='"+obj.name+"']").attr("checked","true");
   		    	} else{   		 		    	
   		    	$("input[name^='"+obj.name+"']").attr("checked","");
   		    	}
		}
		
		
		function refreshuserstatus(){
		
		  

			        $.get("${ctx}/system/SysUser/getAjaxOnlineUsers.do?t="+Math.random(), {            
                    Action:"get",<%=SysConstant.USER_CALL_TYPES%>:"<%=SysConstant.USER_CALL_TYPES_MSG%>"}, function (data, textStatus){	
	      	
                    var temp = eval(data);
                    
                    if(temp == undefined ) return; 
                    if(temp.length ==0 ) return;                   
  
		  		    $("font[name^='chk']").each(function(){  
	      		        
	      		       var temp_color = "black";
	        		   for(var j =0 ; j < temp.length; j++){  	        	

	      		            if(temp[j].uid == ''){continue;}
	      		            
	      		            if( $(this).attr("id") == temp[j].uid){
	      		  
	      		               temp_color = "blue";
	      		               break;
	      		            }
	      		         }
	      		         
	      		          $(this).attr("color",temp_color); 
	                }) ;
             		
		          });	
		
		     parent.showMsg();
		
		}
		function initusers(){
		   refreshuserstatus();
/*
	
	        $.get("${ctx}/system/SysUser/getUserDeptList.do", {	    
	            
            Action:"get",<%=SysConstant.USER_CALL_TYPES%>:"<%=SysConstant.USER_CALL_TYPES_MSG%>"}, function (data, textStatus){	
	      
	         $('#deptuserlist').html("");
	         
	         $('#deptuserlist').append('<table id="chktable" style="width:100%; height:250px;"><tr><td width="150"><strong>部门 </strong> </td><td><strong>人员 </strong> </td></tr></table>');
		
		
			$("a").easyTooltip();
			
             var zNodes = eval(data);
             
             for(var k = 0 ; k < zNodes.length-1;k++){
             
                     var nodes = zNodes[k];    
                     var us = nodes.users;
                     if(nodes.dn == ''){
                        // continue;
                     }
                     var onerow = "<tr><td height=30px;><input type='checkbox' onclick = 'javascript:selectusersbydept(this)' name='chk"+nodes.did+"' value=''/><img src='${ctx}/css/dept.gif'/>"+nodes.dn+"</td><td>";
                     for(var kk =0 ; kk <us.length; kk++){  
                      
                        var status = us[kk].ustatus;
                        onerow += "<label style='width:90px;height:22px'><input type='checkbox' name='chk"+nodes.did+"_"+us[kk].uid+"' value='"+us[kk].uid+"'/><img src='${ctx}/css/user.gif'/><a href='#' id='"+us[kk].uid+"'><font name='chk' id='"+us[kk].uid+"' color='"+status+"'>"+us[kk].un+"</font></a>&nbsp;&nbsp;</label>" ;
         
                     }
                      onerow += "</td></tr>";
                      $("#chktable").append(onerow);                      
             }                
                        for(var k = 0 ; k < zNodes.length;k++){
                        var nodes = zNodes[k];    
                        var us = nodes.users;
        
                        for(var kk =0 ; kk < us.length; kk++){  
                          var status = us[kk].ustatus;
                   		  $("a#"+us[kk].uid+"").easyTooltip({
						  tooltipId: "easyTooltip2",
						  content: ''+us[kk].uinfo
						});                        
                     }                     
                                   
             }    
				});	
				*/
		}
		
	    $(document).ready(function() {
	    
	     initusers();    
	      
	     //全选 
		$("#btn1").click(function(){ 

		 $("input[name^='chk']").attr("checked","true"); 
	    }) 
       //取消全选 
	   $("#btn2").click(function(){ 
		 $("input[name^='chk']").removeAttr("checked"); 
	   })       	        

	        	
	   $("#fileupload").uploadify({	           
	                 'allBytesLoaded':500 * 1024*1024,
	                /*注意前面需要书写path的代码*/ 
	                'uploader'       : '${ctx}/commons/upload/js/uploadify.swf', 
	                'script'         : '${ctx}/files/Files/upload.do', 
	                'cancelImg'      : '${ctx}/commons/upload/images/cancel.png', 
	                'queueID'        : 'fileQueue', //和存放队列的DIV的id一致 
	                'fileDataName'   : 'fileupload', //和以下input的name属性一致 
	                'auto'           : false, //是否自动开始 
	                'multi'          : false, //是否支持多文件上传 
	                'buttonText'     : '选择文件', //按钮上的文字 
	                'simUploadLimit' : 1, //一次同步上传的文件数目 
	                'sizeLimit'      : 300 * 1024 * 1024, //设置单个文件大小限制 
	                'queueSizeLimit' : 1, //队列中同时存在的文件个数限制 
	              
	            onComplete: function (event, queueID, fileObj, response, data) { 
      			     var objs = eval("["+response+"]");	               
	                 form1.uploadedfileid.value = objs[0].uploadedfileid; 	              
					$('<li></li>').appendTo('.files').text(objs[0].uploadedresult); 
	}, 
	       onError: function(event, queueID, fileObj) { 
	             alert("文件:" + fileObj.name + "上传失败"); 
	       }, 
	       onCancel: function(event, queueID, fileObj){ 
	       //    alert("已更改为" + fileObj.name); 
	       } 
	       }); 
	        setInterval("refreshuserstatus()",60000); 
	
	}); 
    function smtform(){    
    	$("input[name^='chk']:checkbox:checked").each(function(){ 
	    	form1.targetids.value +=$(this).val() +",";
	    }) ;
	    if(form1.targetids.value == ''){
	       alert('请选择接收人员!');
           return;
	    }

	    if(form1.content.value == ''){
	  
	       alert('消息不能为空!');
	       return;
	    }
    	form1.submit();
    }
	function uploadifyUpload(){ 
	     if(form1.uploadedfileid.value  != null &&  form1.uploadedfileid.value != ""){
	                   alert("附件已添加!");
	                   
	                   return;
	     }
	   $('#fileupload').uploadifyUpload(); 
	} 
	</script>



	</head>
	<body>

		<div>
	<p>
<label>选择人员(鼠标滑动到人名上查看详细信息)<font color='blue'>在线</font>/离线</label>

                   <input type="button" id="btn1" value="全选" />
				   <input type="button" id = "btn2" value="取消全选" />
				   <input type="button" value="已发消息" onclick="window.location='${ctx}/msg/MsgSend/list.do'" />
				   <input type="button" value="接收消息" onclick="window.location='${ctx}/msg/MsgRecive/list.do'" /> 
</p>
		<div id="deptuserlist" style=" overflow-y:auto; overflow-x:auto; width:100%; height:290px;">
		<%
			// 获得在线用户
	 	String calltypes = request.getParameter(SysConstant.USER_CALL_TYPES);
      
		Set sessions = (HashSet) application.getAttribute(SysConstant.USER_SESSIONS);
		Map umap = new HashMap();
		
		if (sessions != null) {
		
			for (Iterator it = sessions.iterator(); it.hasNext();) {				
				HttpSession sess = (HttpSession) it.next();
				umap.put((String) sess.getAttribute(SysConstant.USER_ID), "");
			}
		}
		
		 List deptlist = (List)session.getAttribute("DEPT_USER_LINK_LIST");
		 
		  %>
				
		  <table id="chktable" style="width:100%; height:250px;"><tr><td width="150"><strong>部门 </strong> </td><td><strong>人员 </strong> </td></tr>
			<script type="text/javascript">
			    $("a").easyTooltip();
			</script>
		
			<%
			if(deptlist != null){ 
			
			for(int i = 0 ; i < deptlist.size()-1;i++){			
			  SysDept dept = (SysDept)deptlist.get(i);
			  List userlist = dept.getUserlist();	 
	

			  
			%>
			    
                  <tr><td height=30px;>
                  <input type='checkbox' onclick = 'javascript:selectusersbydept(this)' name='chk<%= dept.getId() == "" ? (System.currentTimeMillis()+i+""):dept.getId() %>' value=''/><img src='${ctx}/css/dept.gif'/><%=dept.getDeptName() %></td><td> 
                     <%if(userlist != null){ 
                     
                      for(int j = 0 ; j <userlist.size(); j ++){
                      SysUser su = (SysUser)userlist.get(j);

                      		if(SysConstant.USER_CALL_TYPES_MSG.equals(calltypes)){
                                               
							
				    		  
   		    		 }
					 if ((SysConstant.ID_TYPE_DEPT).equals(su.getCardType())){
			    			      continue;
			    		      }   
                      String status = umap.get(su.getId()) == null ? "black": "blue";
                      StringBuffer b = new StringBuffer();
						b.append("姓名:").append(StaticMethod.null2String(su.getUserName()));
						b.append("<br>职务:").append(StaticMethod.null2String(su	.getPosition())).append("<br>电话:").append(StaticMethod.null2String(su.getPhone())).append("<br>手机:").append(StaticMethod.null2String(su.getMobile()));
                      
                      %>        
                        
                       
                        <label style='width:90px;height:22px'><input type='checkbox' name='chk<%=dept.getId() %>_<%=su.getId() %>' value='<%=su.getId() %>'/><img src='${ctx}/css/user.gif'/><a href='#' id='<%=su.getId() %>'><font name='chk' id='<%=su.getId() %>' color='<%=status %>'><%=su.getUserName() %></font></a>&nbsp;&nbsp;</label>
         
					  <script type="text/javascript">
         
           		    	$("a#<%=su.getId()%>").easyTooltip({
						  tooltipId: "easyTooltip2",
						  content: '<%=b.toString()%>'
						});              
         
         					</script>
                               <%
                               }
                               }
                               
                               %>
                  </td></tr>
                                
  
				
				
				
				<%}
				
				} %>
				
				
		</table>
		</div>
			<!--div style="overflow-x:auto;overflow-y:auto; overflow-x:auto; width:600px; height:300px;"-->
				<div>
				<form id="form1" action="${ctx}/msg/MsgSend/save.do" method="post">


					<table class="formTable" >
					    
						<input type="hidden" id="id" name="id" value="${model.id}" />
						<input type="hidden" name="uploadedfileid"
							value="${model.uploadedfileid}" />
						<input type="hidden" id="targetids" name="targetids"
							value="${model.targetids}" />

						<!-- tr>
							<td class="tdLabel" width="30px" >
								<%=MsgSend.ALIAS_TITLES%>:
							</td>
							<td>
								<input id="titles" name="titles" value="${model.titles}"
									type="text" class="easyui-validatebox" />
							</td>
						</tr-->
						<tr>
							<td class="tdLabel" width="30px" >
								<%=MsgSend.ALIAS_CONTENT%>:
							</td>



							<td>
								<textarea id="content" name="content" value="${model.content}"
									class="easyui-validatebox" rows="6" cols="180"
									style="width: 800px"></textarea>    
							</td>
							<td class="tdLabel">
								<input type="button" onclick = "javascript:smtform();" value="发送" />
							</td>
						</tr>

						<!--tr>	
				<td class="tdLabel">
					<%=MsgSend.ALIAS_ACCESSORY%>:
				</td>	
				<td>
					<input type="file" size="30" name="test" />
				</td>
			</tr>

			
			<tr>	
				<td class="tdLabel">
					<%=MsgSend.ALIAS_CREATOR%>:
				</td>	
				<td>
				<input id="creator" name="creator" value="${model.creator}"
				type="text"  class="easyui-validatebox"   />
				</td>
			</tr>
			<tr>	
				<td class="tdLabel">
					<%=MsgSend.ALIAS_CREATE_TIME%>:
				</td>	
				<td>
				<input value="${model.createTimeString}" id="createTimeString" name="createTimeString"  
				type="text" class="easyui-datebox"/>
				</td>
			</tr-->
			</table>
			<div style="font-family:仿宋 ;color:#70aaeb;font-weight:bold;padding-top:1px;padding-left:342px;">
				<ul>提示：数据保存时间为30天<ul>
			</div>
				</form>
				<table>
					<tr >
						<td>
							上传附件(大小限制：300M)：
						</td>
						<td>
							<input type="file" name="fileupload" id="fileupload" />
							<div style="margin-top: 0; width:400px; height: 10px;" id="fileQueue"></div>					
								<a href="javascript:;" onClick="javascript:uploadifyUpload()">开始上传</a>&nbsp;
								<a href="javascript:deleteUploadedFiles();">取消所有上传</a>						
							<ol class=files></ol>
						</td>
				</table>
			</div>

	
	</body>

</html>

